import { MockMethod } from "vite-plugin-mock";

const menus = [
  {
    name: "home",
    path: "/home/index",
    component: "/home/index",
    meta: {
      icon: "home-outlined",
      title: "首页",
      isFull: false,
      isAffix: true,
      isKeepAlive: true
    }
  },
  {
    name: "echarts",
    path: "/echarts",
    redirect: "/echarts/lineChart",
    meta: {
      title: "Echarts",
      icon: "PieChartOutlined",
      isFull: false,
      isKeepAlive: true
    },
    children: [
      {
        name: "lineChart",
        path: "/echarts/lineChart",
        component: "/echarts/lineChart/index",
        meta: {
          title: "折线图",
          icon: "AppstoreOutlined",
          isFull: false,
          isKeepAlive: true
        }
      },
      {
        name: "barChart",
        path: "/echarts/barChart",
        component: "/echarts/barChart/index",
        meta: {
          title: "柱状图",
          icon: "AppstoreOutlined",
          isFull: false,
          isKeepAlive: true,
          isHide: true
        }
      }
    ]
  }
];

const mock: Array<MockMethod> = [
  {
    url: "/login",
    method: "post",
    response: config => {
      const { username, password } = config.body;
      if (username === "admin" && password === "123456") {
        return {
          code: 200,
          msg: "登录成功",
          data: {
            token: "test-01"
          }
        };
      } else {
        return {
          code: -1,
          msg: "账号或密码错误"
        };
      }
    }
  },
  {
    url: "/menus",
    method: "get",
    response: () => {
      return {
        code: 200,
        msg: "成功",
        data: menus
      };
    }
  }
];

export default mock;
